package com.hd.system.common.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hd.enumerate.ResultCode;
import com.hd.system.common.service.FileUploadService;
import com.hd.util.ResultCommonUtils;


@Controller
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;
    

    @RequestMapping(value = "/uploadFileImage", 
			method = RequestMethod.PUT, 
			produces = MediaType.APPLICATION_JSON_VALUE + ";Charset=UTF-8")
	@ResponseBody
	public ResultCommonUtils uploadFileImage(HttpServletRequest request) {
		ResultCommonUtils resultCommon = new ResultCommonUtils();
		try {

			fileUploadService.uploadFileImage(request);
			resultCommon.setCode(ResultCode.SUCCESS.getValue());
			resultCommon.setMessage("SUCCESS");
		} catch (Exception e) {
			resultCommon.setCode(ResultCode.INTERNAL_SERVER_ERROR.getValue());
			resultCommon.setMessage(e.getMessage());
		}
		return resultCommon;
	}
    
    @RequestMapping(value = "/uploadFile", 
			method = RequestMethod.PUT, 
			produces = MediaType.APPLICATION_JSON_VALUE + ";Charset=UTF-8")
	@ResponseBody
	public ResultCommonUtils uploadFile(HttpServletRequest request) {
		ResultCommonUtils resultCommon = new ResultCommonUtils();
		try {

			fileUploadService.uploadFile(request);
			resultCommon.setCode(ResultCode.SUCCESS.getValue());
			resultCommon.setMessage("SUCCESS");
		} catch (Exception e) {
			resultCommon.setCode(ResultCode.INTERNAL_SERVER_ERROR.getValue());
			resultCommon.setMessage(e.getMessage());
		}
		return resultCommon;
	}
}
